<?php

	namespace information\action;

	use herosphp\bean\Beans;
	use herosphp\core\Controller;
	use herosphp\core\WebApplication;
	use herosphp\http\HttpRequest;
	use herosphp\utils\Page;

	/**--tmpl-use--**/

	class NoticeAction extends CommonAction {

		protected $noticeService = null;
		public function C_start()
		{
			$this->assign("index_url", url("/information/notice/index"));
			$this->assign("detail_url", url("/information/notice/detail"));
			$this->noticeService = Beans::get("information.informationNotice.service");
			parent::C_start();
		}

		public function index(HttpRequest $request) {
			$this->pagesize = 4;
			$page = $request->getParameter('page','intval');
			$this->page = $page>0?$page:1;
			$total = $this->noticeService->count(array("release_status"=>1));
			$this->getPagemenu($total,0,'条公告');
			$items = $this->noticeService->getItems(array('release_status'=>1),array(),array(),array($page,$this->pagesize));
			foreach($items as $key=>$item)
			{
				$items[$key]['content'] = strip_tags($item['content']);
			}
			$this->assign('items',$items);

			//如果公告太少，只是推荐少数咨询，以免布局难看
			$limit = count($items)>4?10:4;
			$recommend = $this->inforService->getItems(array('is_recommend'=>1,'release_status'=>1),array(),array('addtime'=>-1),$limit);
			$this->assign('recommend',$recommend);

			$this->setHead("网站公告",'网站公告','网站公告');
            $this->setView(strtolower($request->getAction()) . '/notice_index');
        }
        public function detail(HttpRequest $request) {/*资讯详情*/
			$id = $request->getParameter('id',"intval");
			$item = $this->noticeService->getItem(array('id'=>$id));
			$recommend = $this->inforService->getItems(array('is_recommend'=>1),array(),array(),10);

			//上一篇和下一篇
			$priv = $this->noticeService->getItem(array('addtime'=>array("<"=>$item['addtime'])),array(),array('addtime'=>-1));
			$next = $this->noticeService->getItem(array('addtime'=>array(">"=>$item['addtime'])),array(),array('addtime'=>1));
			$this->assign('priv',$priv);
			$this->assign('next',$next);


			$this->setHead($item['title'],strip_tags($item['content']),strip_tags($item['content']));
			$this->assign('recommend',$recommend);
			$this->assign('item',$item);
            $this->setView(strtolower($request->getAction()) . '/notice_detail');
        }

	}



